package com.example.mydy.model;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.Date;

public class Announcement implements Serializable {
    public static final String STATUS_DRAFT = "draft";
    public static final String STATUS_PUBLISHED = "published";
    public static final String STATUS_ARCHIVED = "archived";

    @SerializedName("id")
    private int id;

    @SerializedName("title")
    private String title;

    @SerializedName("content")
    private String content;

    @SerializedName("publisher")
    private String publisher;

    @SerializedName("publishTime")
    private String publishTime;

    @SerializedName("updatedAt")
    private String updatedAt;

    @SerializedName("status")
    private String status;

    @SerializedName("isTop")
    private boolean isTop;

    @SerializedName("expiryDate")
    private String expiryDate;

    public Announcement() {
        this.status = STATUS_DRAFT;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getPublisher() {
        return publisher;
    }

    public void setPublisher(String publisher) {
        this.publisher = publisher;
    }

    public String getPublishTime() {
        return publishTime;
    }

    public void setPublishTime(String publishTime) {
        this.publishTime = publishTime;
    }

    public String getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(String updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public boolean isTop() {
        return isTop;
    }

    public void setTop(boolean top) {
        isTop = top;
    }

    public String getExpiryDate() {
        return expiryDate;
    }

    public void setExpiryDate(String expiryDate) {
        this.expiryDate = expiryDate;
    }

    public boolean isDraft() {
        return STATUS_DRAFT.equals(status);
    }

    public boolean isPublished() {
        return STATUS_PUBLISHED.equals(status);
    }

    public boolean isArchived() {
        return STATUS_ARCHIVED.equals(status);
    }

    public void setCreatedAt(Date createdAt) {
        if (createdAt != null) {
            java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            this.publishTime = sdf.format(createdAt);
        } else {
            this.publishTime = null;
        }
    }

    public boolean isExpired() {
        if (expiryDate == null || expiryDate.isEmpty()) {
            return false;
        }
        
        try {
            java.time.LocalDate today = java.time.LocalDate.now();
            java.time.LocalDate expiry = java.time.LocalDate.parse(expiryDate);
            return today.isAfter(expiry);
        } catch (Exception e) {
            return false;
        }
    }

    /**
     * 获取发布时间
     * @return 发布时间的字符串表示
     */
    public String getPublishedAt() {
        return publishTime != null ? publishTime : "";
    }
    
    /**
     * 判断公告是否置顶
     * @return 是否置顶
     */
    public boolean isPinned() {
        return isTop;
    }

    @Override
    public String toString() {
        return "Announcement{" +
                "id=" + id +
                ", title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", publisher='" + publisher + '\'' +
                ", publishTime='" + publishTime + '\'' +
                ", status='" + status + '\'' +
                ", isTop=" + isTop +
                ", expiryDate='" + expiryDate + '\'' +
                '}';
    }
} 